set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Tutorial/MathFunctions/lib)  # 设置静态库文件目录
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Tutorial/MathFunctions/lib)  # 动态库文件目录

add_library(MathFunctions src/mysqrt.cxx)

# install(TARGETS MathFunctions DESTINATION lib)  安装命令，将库文件和头文件安装至/usr/local/lib
# install(FILES MathFunctions.h DESTINATION include)  安装至/usr/local/include

# --------------------------------------------->  添加系统自省(System Introspection)

configure_file(Config/TutorialConfig.h.in Config/TutorialConfig.h)

include(CheckSymbolExists)
check_symbol_exists(log "math.h" HAVE_LOG)  # check_symbol_exists(<symbol> <files> <variable>)
check_symbol_exists(exp "math.h" HAVE_EXP)  # 检查一个符号(log/exp)是否在"math.h"中出现，结果存储在<variable>中
if(NOT (HAVE_LOG AND HAVE_EXP))
    unset(HAVE_LOG CACHE)  # 删除变量
    unset(HAVE_EXP CACHE)
    set(CMAKE_REQUIRED_LIBRARIES "m")  # 这个m库是个什么库呢
    check_symbol_exists(log "math.h" HAVE_LOG)
    check_symbol_exists(exp "math.h" HAVE_EXP)
    if(HAVE_LOG AND HAVE_EXP)
        target_link_libraries(MathFunctions PRIVATE m)  # 在m库中找到，进行链接
    endif()
    # 添加表编译器定义
    #if(HAVE_LOG AND HAVE_EXP)
    #    target_compile_definitions(MathFunctions
    #            PRIVATE "HAVE_LOG" "HAVE_EXP")
    #endif()
endif()

# --------------------------------------------->  end
# --------------------------------------------->  打包调试和发布

set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
set_property(TARGET MathFunctions PROPERTY SOVERSION "1")


# --------------------------------------------->  end
